package com.socket.UDP.client;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * 服务器端，基于UDP的用户登陆服务端
 * Created by wangyg on 2016/10/31.
 */
public class UDPClient {
	public static void main(String[] args) throws IOException {
		//定义服务器地址，端口，数据
		InetAddress ia= InetAddress.getByName("localHost");
		int port =8989;
		byte[] data = "用户名：123;密码：123".getBytes();
		DatagramPacket packet=new DatagramPacket(data,data.length,ia,port);
		DatagramSocket socket = new DatagramSocket();
		socket.send(packet);

		//接收响应数据
		byte[] data2= new byte[1024];
		DatagramPacket datagramPacket= new DatagramPacket(data2,data2.length);
		socket.receive(datagramPacket);
		String reply = new String(data2,0,datagramPacket.getLength());
		System.out.println("接收到服务端响应为："+reply);

		socket.close();

	}
}
